package Test1;

import java.util.ArrayList;
import java.util.Collections;

public class lian_xi_Demo4 extends Thread {
    //成员变量
    ArrayList<Integer> list;

    //有参构造方法
    public lian_xi_Demo4(ArrayList<Integer> list) {
        this.list = list;
    }

    /* static ArrayList<Integer> list1 = new ArrayList<Integer>();
     static ArrayList<Integer> list2 = new ArrayList<Integer>();*/
    @Override
    public void run() {
        ArrayList<Integer> boxlist = new ArrayList<>();
        /*
        循环
        同步代码块
        判断
        判断
         */
        while (true) {
            synchronized (Thread_Demo4.class) {
                if (list.size() == 0) {
                  /*  if("线程抽奖1".equals(getName())){
                        System.out.println("线程抽奖1"+list1);
                    }else{
                        System.out.println("线程抽奖2"+list2);
                    }*/
                    System.out.println(getName() + boxlist);
                    break;
                } else {
                    Collections.sort(list);
                    int prize = list.remove(0);
                 /*   if("线程抽奖1".equals(getName())){
                      list1.add(prize);
                   }else{
                    list2.add(prize);}*/
                    boxlist.add(prize);
                }
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


